package com.itholmes.tomcat;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;

import com.itholmes.ServletContext.ServletContext;
import com.itholmes.ServletContext.ServletContextImpl;
import com.itholmes.session.HttpSession;

public class MyTomcat {
	
	//定义端口号
	private int port=8080;

	//用来存放session
	private static Map<String,HttpSession> session = new HashMap<String,HttpSession>();
	
	public void start() {
		try {
			new MyMapping().getServletContext();
			ServerSocket server = new ServerSocket(port);
			//加载驱动
			MyTomcatThread.driverLoad();
			while(true) {
				//实现多线程效果，这里的accept会一直接受前端接受的内容
				Socket socket = server.accept();
				//这里将MyThread构造函数传入一个socket，之后实现多线程。
				new Thread(new MyTomcatThread(socket)).start();;
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		MyTomcat tomcat = new MyTomcat();
		tomcat.start();
	}

	
	public static Map<String, HttpSession> getSession() {
		return session;
	}

	public static void setSession(Map<String, HttpSession> session) {
		MyTomcat.session = session;
	}
	
}
